import CryptoJS from 'crypto-js'
const key = CryptoJS.enc.Utf8.parse("ihaierForTodoKey"); //十六位十六进制数作为秘钥
const iv = CryptoJS.enc.Utf8.parse('ihaierForTodo_Iv'); //十六位十六进制数作为秘钥偏移量
//AES加密
export const encryptByAES = (message) => {
  let srcs = CryptoJS.enc.Utf8.parse(message);
  var encrypted = CryptoJS.AES.encrypt(srcs, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);

}
// AES解密
export const decryptAES = (message) => {
  let base64 = CryptoJS.enc.Base64.parse(message);
  let src = CryptoJS.enc.Base64.stringify(base64);
  var decrypt = CryptoJS.AES.decrypt(src, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });

  var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr.toString();
}